package com.koron.standard.holiday.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.koron.bean.base.Response;
import com.koron.standard.bean.query.PageQuery;
import com.koron.standard.holiday.bean.po.Holiday;
import com.koron.standard.holiday.bean.query.HolidayQuery;
import com.koron.standard.holiday.service.HolidayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 放假日历(Holiday)表控制层
 *
 * @author jzp
 * @since 2023-05-29
 */
@Api(tags = "放假日历接口")
@RestController
@RequestMapping("holiday")
public class HolidayController {

    @Autowired
    private HolidayService holidayService;

    @ApiOperation(value = "分页")
    @GetMapping("page")
    public Response<Page<Holiday>> page(PageQuery<Holiday> pageQuery, HolidayQuery query) {
        return Response.ok(holidayService.page(pageQuery, query));
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping
    public Response<Holiday> select(@RequestParam String id) {
        Holiday holiday = holidayService.getById(id);
        return Response.ok(holiday);
    }

    @ApiOperation(value = "保存")
    @PostMapping
    public Response save(@RequestBody Holiday holiday) {
        holidayService.saveOrUpdate(holiday);
        return Response.ok();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping
    public Response delete(@RequestParam String id) {
        holidayService.removeById(id);
        return Response.ok();
    }
}
